package cn.stylefeng.guns.modular.ha.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.ha.entity.HaApiDeliToStore;
import cn.stylefeng.guns.modular.ha.mapper.HaApiDeliToStoreMapper;
import cn.stylefeng.guns.modular.ha.model.params.HaApiDeliToStoreParam;
import cn.stylefeng.guns.modular.ha.model.result.HaApiDeliToStoreResult;
import  cn.stylefeng.guns.modular.ha.service.HaApiDeliToStoreService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 同步门店送达信息 服务实现类
 * </p>
 *
 * @author zhangzh
 * @since 2025-08-12
 */
@Service
public class HaApiDeliToStoreServiceImpl extends ServiceImpl<HaApiDeliToStoreMapper, HaApiDeliToStore> implements HaApiDeliToStoreService {

    @Override
    public void add(HaApiDeliToStoreParam param){
        HaApiDeliToStore entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(HaApiDeliToStoreParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(HaApiDeliToStoreParam param){
        HaApiDeliToStore oldEntity = getOldEntity(param);
        HaApiDeliToStore newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public HaApiDeliToStoreResult findBySpec(HaApiDeliToStoreParam param){
        return null;
    }

    @Override
    public List<HaApiDeliToStoreResult> findListBySpec(HaApiDeliToStoreParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(HaApiDeliToStoreParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(HaApiDeliToStoreParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private HaApiDeliToStore getOldEntity(HaApiDeliToStoreParam param) {
        return this.getById(getKey(param));
    }

    private HaApiDeliToStore getEntity(HaApiDeliToStoreParam param) {
        HaApiDeliToStore entity = new HaApiDeliToStore();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
